<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>echart</title>
	<script type="text/javascript" src="/static/js/echarts.js"></script>
</head>
<body>
    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
    <div id="main" style="width: 800px;height:600px;"></div>
</body>
</html>
<script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));
        // 指定图表的配置项和数据
        /*var option = {
            title: {
                text: 'ECharts 入门示例'
            },
            tooltip: {},
            legend: {
                data:['销量']
            },
            xAxis: {
                data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }]
        };*/

        // 使用刚指定的配置项和数据显示图表。
         var option = {
            title: {
                text: 'ECharts 入门示例'
            },
            tooltip: {},
            legend: {
                data:['上衣','裤子','太阳伞']
            },
            xAxis: {
                data: ["1月","2月","3月","4月","5月","6月","7月"]
            },
            yAxis: {},
            series: [{
                name: '上衣',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20,35]
                },
                {
                name: '裤子',
                type: 'bar',
                data: [15, 10, 36, 60, 40, 15,10]
                },
                {
                name: '太阳伞',
                type: 'bar',
                data: [5,10, 12, 60, 80, 90,80]
                }
            ]
        };

       var option1 = {
    title : {
        text: '某站点用户访问来源',
        subtext: '纯属虚构',
        x:'center'
    },
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        left: 'left',
        data: ['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']
    },
    series : [
        {
            name: '访问来源',
            type: 'pie',
            radius : '55%',
            center: ['50%', '60%'],
            data:[
                {value:335, name:'直接访问'},
                {value:310, name:'邮件营销'},
                {value:234, name:'联盟广告'},
                {value:135, name:'视频广告'},
                {value:1548, name:'搜索引擎'}
            ],
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};
        myChart.showLoading();
        setTimeout(function(){
        	myChart.hideLoading();
        	myChart.setOption(option1);
        },1500);
        // 图例开关的行为只会触发 legendselectchanged 事件
myChart.on('legendselectchanged', function (params) {
    // 获取点击图例的选中状态
    var isSelected = params.selected[params.name];
    // 在控制台中打印
    console.log((isSelected ? '选中了' : '取消选中了') + '图例' + params.name);
    // 打印所有图例的状态
    console.log(params.selected);
});
// 处理点击事件并且跳转到相应的百度搜索页面
myChart.on('click', function (params) {
    alert(params.name);
});
    </script>